<template>
    <div class="login">
        <h2 class="title">
            欢迎来到量化交易平台!
        </h2>
        <div class="my-input">
            <svg class="icon" aria-hidden="true">
                <use xlink:href="#icon-user"></use>
            </svg>
            <input type="text" v-model="account" placeholder="username" autocomplete="off" maxlength="8">
        </div>
        <div class="my-input">
            <svg class="icon" aria-hidden="true">
                <use xlink:href="#icon-icons-"></use>
            </svg>
            <input type="password" v-model="password" placeholder="password" autocomplete="off">
        </div>
        <el-button round @click="login">log in &nbsp;&nbsp;<i class="el-icon-arrow-right"></i></el-button>
        <div class="footer">
            <p>No account yet?</p>
            <p style="color:rgb(229,163,89);cursor:pointer;" @click.prevent="$emit('toggle')">sign up</p>
        </div>
    </div>
</template>
<script>
export default {
    name: 'login',
    data(){
        return{
            account: '',
            password: '',
        }
    },
    methods:{
        login(){
           if(this.account ==''||this.password ==''){
               this.$message({
                   message: '账号密码不能为空',
                   center: true,
                   type: 'warning'
               })
           }else{
               this.$http.post('/api/iStudy/login/doLogin.do',{
                   uNo : this.account,
                   uPwd: this.password
               }).then(ret => {
                   if(ret.body.status == 0){
                        this.$message({
                            message: '账号密码错误',
                            center: true,
                            type: 'error'
                        })
                    }else if(ret.body.status == 2){
                        this.$message({
                            message: '网络错误，请稍后重试',
                            center: true,
                            type: 'error'
                        })
                    }else{
                        this.$http.get('api/iStudy/user/info').then(ret => {
                            this.$store.commit('setAll',ret.body)
                            this.$store.commit('setOne',{
                                name: 'loginFlag',
                                value: true,
                            })
                            //console.log(this.$store.state.loginFlag)
                        })
                        this.$router.push({path:'/home'})
                    }
            })
                
        }
    }
}
}
</script>
<style scoped>
    .login{
        position: absolute;
        left: 20%;
        top: 20%;
        width:400px;
        height: 450px;
    }
    h2{
        line-height: 50px;
        text-align: center;
        margin-bottom: 17%;
        font-weight: 600;
    }
    .my-input{
        width: 80%;
        height: 64px;
        line-height: 64px;
        margin: 0% auto;
        text-align: center;
        border-bottom: 1px solid #dfdfdf;
    }
    .my-input input{
        width: 260px;
        height: 34px;
        line-height: 34px;
        border: 1px solid #fff;
        font-size: 18px;
        text-indent: 1.7em;
    }
    .my-input input:focus{
        outline: none;
    }
    .icon {
        width: 1.3em;
        height: 1.3em;
        vertical-align: -0.2em;
        fill: currentColor;
        overflow: hidden;
    }
    .el-button{
        width: 130px;
        display: block;
        margin: 20% auto 0px;
        background-color: rgb(136,202,201);
        color: #efefef;
        text-align: center;
    }
    .el-button:active{
        border-color: rgb(76, 160, 132);
        color: #fff;
    }
    .footer{
        display: flex;
        justify-content: space-around;
        margin-top: 44px;
    }
</style>